<template>
  <el-menu
     ref="menuRef"
    :default-active="activeIndex"
    class="el-menu-demo"
    mode="horizontal"
    :ellipsis="false"
    @select="handleSelect"
    menu-trigger="click"
  >
    <el-menu-item index="0">
      <img
        style="width: 200px;height: 60px;"
    
        src="/src/assets/logo.jpg"
        alt="lengyu logo"
      />
    </el-menu-item>
     <el-sub-menu index="1" >
      <template #title>{{ currentCompany }}</template>
      <el-menu-item index="铁建工科">铁建工科</el-menu-item>
      <el-menu-item index="康得利">康得利</el-menu-item>
    </el-sub-menu>
    <el-sub-menu index="2">
      <template #title>{{ currentSys }}</template>
      <el-menu-item index="客户管理系统">客户管理系统</el-menu-item>
      <el-menu-item index="项目管理系统">项目管理系统</el-menu-item>
      <el-menu-item index="后台管理系统">后台管理系统</el-menu-item>
      <el-menu-item index="小程序后台管理系统">小程序后台管理系统</el-menu-item>
    </el-sub-menu>
    <el-menu-item index="3">
         <el-avatar :size="50" :src="circleUrl" />
    </el-menu-item>
    <el-sub-menu index="4"  >
      <template #title>{{ userName }}</template>
      
      <el-menu-item index="4-1" @click="handleLogout">退出</el-menu-item>
    </el-sub-menu>
  </el-menu>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import type { MenuInstance } from 'element-plus';
import { useAuthStore } from '@/stores/auth'



const activeIndex = ref('1')
const menuRef = ref<MenuInstance>();

const handleSelect = (key: string, keyPath: string[]) => {
  activeIndex.value=key
  console.log("key",key)
  console.log("keyPath",keyPath)
  if(keyPath[0] == '2'){
    console.log("选择系统：" ,key)
    currentSys.value=key
  }
  else if(keyPath[0]=='1'){
    console.log("选择企业：" ,key)
    currentCompany.value=key
  }

  
}
const circleUrl = ref('https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png');
const userName=ref('');
const currentSys=ref('客户管理系统')
const currentCompany=ref('铁建工科')
userName.value="冷羽"

const handleLogout = async () => {
    useAuthStore().logout()
    location.reload()
}


</script>

<style scoped>
.el-menu--horizontal > .el-menu-item:nth-child(1) {
  margin-right: auto;
}
</style>